﻿(function () {
    var d = document,
    isStrict = d.compatMode == "CSS1Compat",
    dd = d.documentElement,
    db = d.body,
    m = Math.max,
    ie = !!d.all,
    ua = navigator.userAgent.toLowerCase(),
    ff = /firefox/.test(ua),
    head = d.getElementsByTagName('head')[0],
    getWH = function () {
        return {
            h: (isStrict ? dd : db).clientHeight,
            w: (isStrict ? dd : db).clientWidth
        }
    },
    getS = function () {
        return {
            t: m(dd.scrollTop, db.scrollTop),
            l: m(dd.scrollLeft, db.scrollLeft)
        }
    },
    getP = function (a) {
        var r = {
            t: 0,
            l: 0
        },
        isGecko = /gecko/.test(ua),
        add = function (t, l) {
            r.l += l,
            r.t += t
        },
        p = a,
        sTL = getS();
        if (a && a != db) {
            if (a.getBoundingClientRect) {
                var b = a.getBoundingClientRect();
                add(b.top + sTL.t - dd.clientTop, b.left + sTL.l - dd.clientLeft)
            } else {
                var c = d.defaultView;
                while (p) {
                    add(p.offsetTop, p.offsetLeft);
                    var e = c.getComputedStyle(p, null);
                    if (isGecko) {
                        var f = parseInt(e.getPropertyValue('border-left-width'), 10) || 0,
                        bt = parseInt(e.getPropertyValue('border-top-width'), 10) || 0;
                        add(bt, f);
                        if (p != a && e.getPropertyValue('overflow') != 'visible') add(bt, f)
                    }
                    p = p.offsetParent
                }
                p = a.parentNode;
                while (p && p != db) {
                    add(-p.scrollTop, -p.scrollLeft);
                    p = p.parentNode
                }
            }
        }
        return r
    },
    creElm = function (o, t, a) {
        var b = d.createElement(t || 'div');
        for (var p in o) {
            p == 'style' ? b[p].cssText = o[p] : b[p] = o[p]
        }
        return (a || db).insertBefore(b, (a || db).firstChild)
    },
    div = creElm({
        id: 'ckepop',
        style: "position:absolute;z-index:100000;display:none"
    }),
    div1 = creElm({
        id: 'ckepop',
        style: "position:absolute;z-index:100000;display:none;top:50%;left:50%;overflow:auto"
    }),
    timer,
    inputTimer,
    list,
    clist,
    as,
    texts = {},
    iframe,
    tagImgs = ["jiathis.gif", "jiathis1.gif", "jiathis2.gif", "jiathis3.gif", "jiathis4.gif", "jiathis5.gif", "jiathis6.gif"],
    scripts = d.getElementsByTagName('script');
    for (var i = 0, ci, Bn; ci = scripts[i++];) {
        if (Bn = ci.src.match(/Bn=(\d)$/)) {
            break
        }
    };
    creElm({
        href: 'http://www.jiathis.com/code/css/css1.css',
        rel: 'stylesheet',
        type: 'text/css'
    },
    'link');
    d.write('<a href="#" onmouseover="return $CKE.over(this)" onmouseout="return $CKE.out()" onmousemove="$CKE.move()" onclick="return $CKE.center()"><img src="http://www.jiathis.com/code/images/' + tagImgs[(Bn && Bn[1]) || 0] + '" width="125" height="21" border="0" id="jiathis_a"/></a>');
    $CKE = {
        pop: div,
        centerpop: div1,
        disappear: function (b) {
            var c = window.event || b,
            t = c.srcElement || c.target,
            contain = div1.contains ? div1.contains(t) : !!(div1.compareDocumentPosition(t) & 16),
            a = d.getElementById('jiathis_a'),
            contain1 = div.contains ? div.contains(t) : !!(div.compareDocumentPosition(t) & 16);
            if (!contain && !contain1 && t != a) {
                div1.style.display = 'none';
               iframe&&(iframe.style.display= 'none');
                ff&&(div1.style.position='absolute');
            }
        },
        over: function (a) {
        	var s,T = this,fn = function(){
        		var p = getP(T.a),
           	 	wh = getWH(),
	            tl = getS();
	            with(div.style) {
	                display = "block";
	                top = (p.t + T.a.offsetHeight + div.offsetHeight > wh.h + tl.t ? p.t - div.offsetHeight - (ie ? 1 : 8) : p.t + T.a.offsetHeight + 1) + 'px';
	                left = p.l + 'px'
	            }
        	};
            if (!this.a) {
                this.a = a;
                s = creElm({
                    src: 'http://www.jiathis.com/code/ckepop.js',
                    charset: 'utf-8'
                },
                'script', head);
                s.onloaded = 0;
                s.onload = function(){s.onloaded=1;fn()};
                s.onreadystatechange = function(){
                	if(s.readyState =='loaded'&&!s.onloaded){
                		fn();
                	}
                }
            }else{
            	fn();
            }
            
            
            return false
        },
        out: function () {
            timer = setTimeout(function () {
                div.style.display = 'none'
            },
            100)
        },
        move: function () {
            clearTimeout(timer)
        },
        center: function () {
            div.style.display = 'none';
            if (!this.script) {
                this.script = creElm({
                    src: 'http://www.jiathis.com/code/ckecenterpop.js',
                    charset: 'utf-8'
                },
                'script', head);
                db.style.position = 'static'
            } else {
                var a = getS();
                div1.style.display = "block";
                div1.style.margin = (-div1.offsetHeight / 2 + a.t) + "px " + (-div1.offsetWidth / 2 + a.l) + "px";
                ff&&(div1.style.position='fixed');
                list = d.getElementById('ckelist'),
                clist = list.cloneNode(true),
                as = clist.getElementsByTagName('input');
                for (var i = 0, ci; ci = as[i++];) {
                    texts[ci.value] = ci.parentNode
                };
               	if(!ff){
                	!iframe&&(iframe = creElm({
                		style:'position:absolute;top:'+div1.offsetTop+'px;left:'+div1.offsetLeft+'px;width:'+div1.offsetWidth+'px;height:'+div1.offsetHeight+'px',
                		frameBorder:0
                	},'iframe'));
                	iframe.style.display= 'block';
                }
            }
            return false
        },
        choose: function (o) {
            clearTimeout(inputTimer);
            inputTimer = setTimeout(function () {
                var s = o.value.replace(/^\s+|\s+$/, ''),
                frag = d.createDocumentFragment();
                for (var p in texts) {
                    eval("var f = /" + (s || '.') + "/ig.test(p)");
                    f && frag.appendChild(texts[p].cloneNode(true))
                }
                list.innerHTML = '';
                list.appendChild(frag)
            },
            100)
        },
        centerClose: function () {
            div1.style.display = 'none';
             iframe&&(iframe.style.display= 'none');
             ff&&(div1.style.position='absolute');
        }
    };
    div.onmouseover = function () {
        clearTimeout(timer)
    };
    div.onmouseout = function () {
        $CKE.out()
    };
    ie ? d.attachEvent("onclick", $CKE.disappear) : d.addEventListener("click", $CKE.disappear, false)
})();
function jiathis_sendto(m) {
    window.open('http://www.jiathis.com/send/?webid=' + m + '&url=' + encodeURIComponent(location) + '&title=' + encodeURIComponent(document.title), '');
    return false
};
function jt_copyUrl() {
    var a = this.location.href;
    var b = document.title;
    if (window.clipboardData) {
        var c = b + "\n" + a;
        var d = window.clipboardData.setData("Text", c);
        if (d) alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友！")
    } else {
        alert("目前只支持IE，请复制地址栏URL,推荐给你的QQ/MSN好友！")
    }
};
function jt_addBookmark(a) {
    var b = parent.location.href;
    if (window.sidebar) {
        window.sidebar.addPanel(a, b, "")
    } else if (document.all) {
        window.external.AddFavorite(b, a)
    } else if (window.opera && window.print) {
        return true
    }
}